<!--
 * @Author: Wangtao
 * @Date: 2020-11-26 20:50:52
 * @LastEditors: Wangtao
 * @LastEditTime: 2021-03-26 16:31:03
-->
<template>
  <div style="height: 100%">
    <callSummary
      inputType="INSERT"
      :componentHeight="213"
      :propData="callData"
      :randomNum="randomNum"
      moduleType="myPreviewTask"
      @changeCustomerRelation="changeCustomerRelation"
      :shadow='false'
      :showListen="showListen"
      :showDowload="showDowload"
    ></callSummary>
  </div>
</template>

<script lang="ts">
import CallSummary from '@/components/commonSummary/index.vue'
import { Component, Vue, Watch } from 'vue-property-decorator'
import { CallCardModule } from '@/store/modules/cti/callCard'
import { checkPermission } from '@/utils/directive'

@Component({ name: 'CallSummaryByCallData', components: { CallSummary } })
export default class CallSummaryByCallData extends Vue {
  private $route: any
  private $bus: any
  private $router: any
  private callData: any = {}
  private randomNum = 0
  private showDowload: boolean = false
  private showListen: boolean = false

  get currentOutboundObj (): any {
    return JSON.parse(JSON.stringify(CallCardModule.currentOutboundObj))
  }

  @Watch('currentOutboundObj', { immediate: true })
  private currentOutboundObjChange (callObj, oldObj) {
    if (!callObj || !callObj.custName) {
      return
    }
    if (callObj && callObj.body && callObj.body.callType !== 'previewDialout') { // 不是预览外呼类型的，排除掉
      return
    }
    if (oldObj && oldObj.id && callObj.id === oldObj.id) { // 若id相同不再刷新弹屏，之前是状态一更新，弹窗内就重载。
      return
    }
    if (!callObj.id) {
      return
    }
    this.$set(this, 'callData', {
      importType: 'CallCard', // 数据中心 - 通话记录
      timeStamp: new Date().getTime(),
      phone: callObj.phoneNum,
      custId: callObj.custId,
      custName: callObj.custName,
      customerList: callObj.locateCust || [],
      callSheetId: callObj.id,
      cdr: callObj.body,
      cdrName: 'cdr_outbound'
    })
    this.randomNum = Math.random() + 1
  }

  private changeCustomerRelation (info) {
    CallCardModule.updateCardInfo(info)
  }

  private beforeMount () {
    if (checkPermission(null, { value: ['my_call_task_list_voice_database_audition'] })) { //  试听，下载（我的预览外呼弹屏内的权限控制)
      this.showListen = true
      if (checkPermission(null, { value: ['my_call_task_list_voice_database_download'] })) {
        this.showDowload = true
      }
    }
  }
}
</script>

<style lang="stylus" scoped></style>
